<template>
	<view class="wrap">
		<view class="wrap_top">
			<view class="title">
				<view class="">
					{{regnoInfo.entname}}
				</view>
			</view>
			<view class="con">统一社会信用代码/注册号： {{regnoInfo.regno}}</view>
			<view class="btn" v-if="sonList.length>0">
				<u-button text="切换子公司" color="#A67315" size="small" @click="$refs.cutPop.open()"></u-button>
			</view>
		</view>
		<view class="middle">
			<view class="title">年报列表</view>
			<view class="conA">
				{{yesteryear}}年度年报状态：
				<text class="state" :style="yesterstate==2?'color: #00C260;':''">{{$util.stateText(yesterstate)}}</text>
			</view>
			<view class="hint">请在{{year}}年{{cutOffTimer.month}}月{{cutOffTimer.day}}日之前完成年报申报</view>
		</view>
		
		<scroll-view scroll-y="true" class="content">
			<YSteps 
				lineNum='0' 
				backgroundColor='#FFF' 
				borderColor="#2589FF" 
				lineColor="#E4E4E4" 
				:infoList='list'
				@click="YStepsClick"
			></YSteps>
		</scroll-view>
		
		<uni-popup ref="cutPop">
			<view class="popWrap">
				<view class="title">切换子公司</view>
				<view class="pop_con u-cell-group_wrap">
					<view class="tit" style="margin-top: 0;">母公司</view>
					<u-cell-group>
						<u-cell :title="parentRegnoInfo.entname" :label="parentRegnoInfo.regno" :clickable="true" center @click.stop="cutCompany(parentRegnoInfo)">
							<u-tag slot="right-icon" :text="parentRegnoInfo.regno==regnoInfo.regno?'当前公司':'切换公司'" @click.stop="cutCompany(parentRegnoInfo)" :type="parentRegnoInfo.regno==regnoInfo.regno?'success':'warning'" plain size="mini"></u-tag>
						</u-cell>
					</u-cell-group>
					<view class="tit">子公司</view>
					<u-cell-group>
						<u-cell v-for="item,index in sonList" :key="index" :title="item.entname" :label="item.regno" :clickable="true" center @click.stop="cutCompany(item)">
							<u-tag slot="right-icon" :text="item.regno==regnoInfo.regno?'当前公司':'切换公司'" @click.stop="cutCompany(item)" :type="item.regno==regnoInfo.regno?'success':'warning'" plain size="mini"></u-tag>
						</u-cell>
					</u-cell-group>
				</view>
			</view>
		</uni-popup>
		
		<uni-popup ref="message" type="message">
			<uni-popup-message :type="msgType" :message="messageText" :duration="5000" style="text-align: center;"></uni-popup-message>
		</uni-popup>
		
		<u-modal :show="modalShow" title="提示" :showCancelButton="true" @confirm="cutCompanySubmit()" @cancel="modalShow=false" >
			<view class="slot-content">
				<view class="">确定要切换公司为 <text style="color: #A67315; font-weight: bold;">{{selectCompany.entname}}</text> 进行年报填报吗？</view>
				<view style="color: red; margin-top: 20rpx;">注：只有在年报填报时，可以切换所要填报的公司，退出、重新进入都将自动切换回登录时的公司。</view>
			</view>
		</u-modal>
		
	</view>
</template>

<script>
import YSteps from '../../components/Y-Steps/Y-Steps.vue'
export default {
	components: {YSteps},
	data(){
		return{
			parentRegnoInfo: this.$store.state.parentRegnoInfo,
			regnoInfo: this.$store.state.regnoInfo,
			cutOffTimer: this.$typeData.cutOffTimer,
			year: '',
			yesteryear: '',
			yesterstate: '',
			list: [],
			msgType: 'error',
			messageText: '',
			
			sonList: [],
			modalShow: false,
			selectCompany: {},
		}
	},
	onLoad() {
		if(!this.$store.state.backState){
			let parentRegnoInfo = this.$store.state.parentRegnoInfo;
			this.$store.commit('setRegnoInfo',parentRegnoInfo);
			this.regnoInfo = parentRegnoInfo;
		}else{
			this.$store.commit('setBackState',false);
		}
		
		this.getNowYear();
		this.getList();
		this.getSonList();
	},
	methods:{
		cutCompanySubmit(){
			this.$store.commit('setRegnoInfo',this.selectCompany);
			this.regnoInfo = this.selectCompany;
			this.list = [];
			this.getList();
			this.modalShow = false;
			this.$refs.cutPop.close();
		},
		cutCompany(item){
			let _this = this;
			if(item.regno == this.regnoInfo.regno) return;
			this.selectCompany = item;
			this.modalShow = true;
		},
		getSonList(){
			let regno = this.parentRegnoInfo?this.parentRegnoInfo.regno:this.regnoInfo.regno;
			this.$http.sendRequest({
				url: '/annual/report/marpripinfo/has-children',
				data: {
					regno: regno
				},
				hideLoad: true,
			})
			.then(res=>{
				let arr = res.data;
				this.sonList = arr;
				console.log(555,res)
			})
			.catch(err=>{})
		},
		showMessage(){
			// this.messageText = '有未填报信息，请及时填报';
			this.messageText = `${this.yesteryear}年度年报尚未填报，请及时填报`;
			this.$refs.message.open()
		},
		getNowYear(){
			let date = new Date();
			this.year = date.getFullYear();
			this.yesteryear = date.getFullYear()-1;
		},
		getList(){
			this.$http.sendRequest({
				url: '/annual/report/baseinfo/list',
				data: {
					regno: this.regnoInfo.regno,
					uniscid: this.regnoInfo.uniscid,
				}
			})
			.then(res=>{
				let arr = res.data;
				let notSta = false;
				
				arr.forEach(item=>{
					if(item.ancheyear == this.yesteryear){
						notSta = true;
						this.yesterstate = item.state;
					}
					item.YSteps_date = item.ancheyear;
					item.YSteps_textTit = `年报信息` + this.$util.stateText(item.state);
					// item.YSteps_textTime = `${item.anchedate?this.$util.timeStampFour(item.anchedate/1000,true,'-'):'暂未'}完成年报`;
					item.YSteps_textTime = `${item.state=='02'?'已':'暂未'}完成年报`;
					// item.YSteps_state = (item.state === '01' || item.state === '02' || item.state === '03') ? true:false;
					// 更改为不超时皆可填写↓↓↓
					item.YSteps_state = item.state === '02' ? true:false;
					item.YSteps_stateText = this.$util.stateText(item.state);
				})
				arr = arr.reverse();
				if(!notSta){
					let obj = {
						YSteps_date: this.yesteryear,
						YSteps_textTit: '',
						YSteps_textTime: '',
						YSteps_state: false,
						YSteps_stateText: '未年报',
						state: '00'
					}
					arr.unshift(obj);
					this.yesterstate = false;
				}
				// let fillInSta = false;
				// arr.forEach(item=>{
				// 	if(item.state == '00' || !item.state){
				// 		fillInSta = true;
				// 	}
				// })
				// if(fillInSta){
				// 	this.showMessage();
				// }
				this.list = arr;
				if(this.yesterstate!=2){
					this.showMessage();
				}
			})
			.catch(err=>{})
		},
		YStepsClick(e){
			console.log(e);
			// this.$store.commit('setAnnalsData',e)
			uni.navigateTo({
				url: `/pages/annals/index?year=${e.YSteps_date}&state=${e.state}`,
			})
		}
	}
}
</script>

<style lang="less">
.wrap{
	width: 100vw;
	height: 100vh;
	padding-top: 16rpx;
	box-sizing: border-box;
	background-color: #F5F6F8;
}
.wrap_top{
	width: 100%;
	min-height: 138rpx;
	box-sizing: border-box;
	padding: 16rpx 36rpx;
	background-color: #FFF;
	margin-bottom: 16rpx;
	
	.title{
		min-height: 40rpx;
		font-size: 40rpx;
		font-weight: bold;
		color: #A67315;
	}
	.con{
		font-size: 26rpx;
		color: #b6b6b6;
		margin-top: 20rpx;
	}
	.btn{
		width: 270rpx;
		height: 64rpx;
		margin-top: 20rpx;
	}
}
.middle{
	width: 100%;
	height: 214rpx;
	box-sizing: border-box;
	padding: 16rpx 32rpx;
	background-color: #FFF;
	margin-bottom: 16rpx;
	
	.title{
		font-size: 38rpx;
		color: #E4B269;
		border-bottom: 2rpx solid #E4B269;
		padding-bottom: 10rpx;
		padding-left: 10rpx;
	}
	.conA{
		font-size: 32rpx;
		padding-left: 10rpx;
		margin-top: 30rpx;
		
		.state{
			color: red;
		}
	}
	.hint{
		font-size: 28rpx;
		padding-left: 10rpx;
		color: #b6b6b6;
		margin-top: 10rpx;
	}
}

.content{
	width: 100%;
	height: calc(100vh - 486rpx);
	padding: 10rpx 0 20rpx 10rpx;
	box-sizing: border-box;
}

.popWrap{
	width: 80vw;
	height: 60vh;
	background-color: #FFF;
	border-radius: 20rpx;
	position: relative;
	
	.title{
		padding: 30rpx;
		font-size: 36rpx;
		font-weight: bold;
		text-align: center;
	}
	
	.pop_con{
		height: calc(50vh - 110rpx);
		box-sizing: border-box;
		padding: 30rpx 20rpx;
		overflow: hidden;
		overflow-y: auto;
		
		.tit{
			color: #E4B269;
			font-size: 36rpx;
			font-weight: bold;
			border-left: 8rpx solid #E4B269;
			line-height: 40rpx;
			padding-left: 16rpx;
			margin-bottom: 16rpx;
			margin-top: 30rpx;
		}
	}
	
	.button{
		width: 100%;
		height: 90rpx;
		position: absolute;
		bottom: 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 32rpx;
		font-weight: bold;
		color: #fff;
		border-top: 2rpx solid rgba(0, 0, 0, 0.3);
		
		view{
			width: 50%;
			height: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
		}
		.cancel{
			border-right: 2rpx solid #fff;
			background-color: #c1c1c1;
			border-radius: 0 0 0 20rpx;
		}
		.confirm{
			background-color: #E4B269;
			border-radius: 0 0 20rpx 0;
		}
	}
}

.u-cell-group_wrap{
	.u-cell__body{
		padding: 10rpx !important;
	}
	.u-cell__title-text{
		color: #222 !important;
		font-weight: bold !important;
	}
	.u-cell__label{
		font-size: 28rpx !important;
		color: #595959 !important;
	}
}


</style>